package com.cy.springboot04notice.service.impl;

import com.cy.springboot04notice.common.annotation.RequiredLog;
import com.cy.springboot04notice.dao.SysLogDao;
import com.cy.springboot04notice.pojo.SysLog;
import com.cy.springboot04notice.service.SysLogService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysLogServiceImpl implements SysLogService {

    @Resource
    private SysLogDao sysLogDao;

    //不能添加日志记录注解，因为死循环
    @Async
    @Override
    public void saveLog(SysLog sysLog) {
        sysLogDao.insertLog(sysLog);
    }

    @RequiredLog(operation = "删除日志")
    @Override
    public int deleteLogs(Integer... ids) {
        int i = sysLogDao.deleteById(ids);
        return i;
    }

    @RequiredLog(operation = "查询日志")
    @Override
    public SysLog findById(Integer id) {
        SysLog sysLog = sysLogDao.selectById(id);
        return sysLog;
    }

    @RequiredLog(operation = "查询日志列表")
    @Override
    public List<SysLog> findByIds(SysLog sysLog) {
        List<SysLog> sysLogs = sysLogDao.selectLogs(sysLog);
        return sysLogs;
    }
}
